const sql = require('../../sql/sqlConfig');
const express = require('express');
let router = express.Router();

const tokenObj = require('../../util/jwt');
let myToken = new tokenObj();

//查分销商等级
router.get('/rule', function (req, res, next) {
    let option = "select * from `level_setting`";
    sql.query(option, function (err, rows) {
        if (err) return res.send({errCode:-9999,message:'操作数据库失败'+err});
        if(!rows[0]) return res.send({errCode:9,message:'登记表为空'});
        let minLevel = rows[0].proportion.replace("%","")/100;
        let result = rows.map((val,index,arr)=>{
            return {
                id:val.id,
                level:val.level,
                order_num:val.order_num,
                proportion:((val.proportion.replace("%","")/100)/minLevel).toFixed(2)*100+'%'
            }
        });
        res.send({errCode:0,message:'查询分销商等级成功',result:result});
    })
});

module.exports = router;
